package com.ahdy.service.impl;

import com.ahdy.entity.GoodPeople;
import com.ahdy.mapper.GoodPeopleMapper;
import com.ahdy.service.GoodPeopleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 好人服务实现类
 */
@Service
public class GoodPeopleServiceImpl implements GoodPeopleService {

    @Autowired
    private GoodPeopleMapper goodPeopleMapper;

    @Override
    @Transactional
    public Integer addGoodPeople(GoodPeople goodPeople) {
        goodPeopleMapper.insert(goodPeople);
        return goodPeople.getId();
    }

    @Override
    @Transactional
    public int updateGoodPeople(GoodPeople goodPeople) {
        return goodPeopleMapper.update(goodPeople);
    }

    @Override
    @Transactional
    public int deleteGoodPeople(Integer id) {
        return goodPeopleMapper.deleteById(id);
    }

    @Override
    public GoodPeople getGoodPeopleById(Integer id) {
        return goodPeopleMapper.findById(id);
    }

    @Override
    public List<GoodPeople> getAllGoodPeople() {
        return goodPeopleMapper.findAll();
    }

    @Override
    public GoodPeople getGoodPeopleByPhone(String phone) {
        return goodPeopleMapper.findByPhone(phone);
    }

    @Override
    public GoodPeople login(String phone, String password) {
        return goodPeopleMapper.findByPhoneAndPassword(phone, password);
    }

    @Override
    public List<GoodPeople> getGoodPeopleByElderlyId(Integer elderlyId) {
        return goodPeopleMapper.findByElderlyId(elderlyId);
    }

    @Override
    public List<GoodPeople> getGoodPeopleByThing(String thing) {
        return goodPeopleMapper.findByThing(thing);
    }
}